import org.example.Business.studentService;
import org.example.Model.student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/HelloServlet")
public class HelloServlet extends HttpServlet {

    studentService service;
    student stu;
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String Sno = request.getParameter("Sno");
        String Sname = request.getParameter("Sname");
        String Ssex = request.getParameter("Ssex");
        int  Sage= Integer.parseInt(request.getParameter("Sage"));
        String Sdept= request.getParameter("Sdept");
       stu.setSno(Sno);
       stu.setSname(Sname);
       stu.setSsex(Ssex);
       stu.setSage(Sage);
       stu.setSdept(Sdept);

        service.insert(stu);

        PrintWriter out = response.getWriter();

        out.println(Sno);
        out.println(Sname);
        out.println(Ssex);
        out.println(Sage);
        out.println(Sdept);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();

        out.println("From Servlet!");

    }

    @Autowired
    public void setService(studentService service) {
        this.service = service;
    }
    @Autowired

    public void setStu(student stu) {
        this.stu = stu;
    }
}
